<?php

/**
 * 客户地址管理
 */
namespace app\client\services;

use app\admin\model\AddressModel;
use think\facade\Validate;

class AddressService extends \app\admin\services\BaseService
{
    public static function index($p){
        $params=[
            'where'=>[
                ['customer_id','=',$p['customer_id']]
            ],
            'page'=>'all'
        ];
        $list=AddressModel::getList($params);
        api_return(200,'',['list'=>$list]);
    }
    public static function edit($p){
        $rule=[
            'address'=>'require',
            'tel'=>'require',
            'nickname'=>'require',
            'lng'=>'require',
            'lat'=>'require',
        ];
        $validate=Validate::rule($rule);
        if(!$validate->check($p)){
            api_return(500,$validate->getError());
        }
        AddressModel::edit($p);
    }
    public static function del($p){
        $rule=[
            'id'=>'require',
        ];
        $validate=Validate::rule($rule);
        if(!$validate->check($p)){
            api_return(500,$validate->getError());
        }
        AddressModel::delByIds($p['id']);
    }

}
